package com.baizhi.action;

import com.baizhi.entity.Employee;
import com.baizhi.service.EmployeeService;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import java.util.Date;
import java.util.List;

@Controller("employeeAction")
@Scope("prototype")
public class EmployeeAction extends ActionSupport {
//成员变量
    private List<Employee> employees;
    private Employee employee;
    private Date birthday;
    private int totalPage; //总页数
    //接收数据   页号
    private int pageNumber=1;
    //收集要删除的eid 号
    private int[] eids;

    @Autowired
    private EmployeeService employeeService;


    //1、 批量删除
    public String plRemove(){

        if (eids!=null){
            employeeService.plDelete(eids);
        }
        return Action.SUCCESS;
    }


    //2、 分页查询
    public String findByPage(){

        employees = employeeService.queryByPage(pageNumber);
        //2、获取总页数
        totalPage = employeeService.getTotalPage();

        //跳转页面
        return "successSelectAll";
    }


    //3、 移除
    public String remove(){

       employeeService.drop(employee.getEid());
        return ActionSupport.SUCCESS;
    }


    //4、 添加
    public String add(){

       employeeService.add(employee);

       return ActionSupport.SUCCESS;
    }


    //5、 查询一条员工数据
    public String queryone(){

        employee = employeeService.queryOne(this.employee.getEid());

        return "queryoneSuccess";
    }

    //6、 更新
    public String update(){

       employeeService.modify(employee);

       return Action.SUCCESS;
    }



//GET/SET

    public List<Employee> getEmployees() {
        return employees;
    }

    public void setEmployees(List<Employee> employees) {
        this.employees = employees;
    }

    public Employee getEmployee() {
        return employee;
    }

    public void setEmployee(Employee employee) {
        this.employee = employee;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

    public int[] getEids() {
        return eids;
    }

    public void setEids(int[] eids) {
        this.eids = eids;
    }
}
